package call;

import java.util.concurrent.Callable;

/**
 * @classname:MoneyCallable
 * @description:
 * @author: Mr.Z
 * @date: 2020/12/19 10:17
 * @version: 0.1
 * @since:1.8
 */
public class MoneyCallable implements Callable<Integer> {
    private Integer balance = 1000;
    private boolean flag ;
    private Integer money ;
    @Override
    public Integer call() throws Exception {

        if(flag){
//转钱
            balance+=money;
            System.out.println(Thread.currentThread().getName()+"向张三转了"+money+"块钱余额"+balance);
        }else {
//收钱
            balance-=money;
            System.out.println("我转了"+money+"块钱给"+Thread.currentThread().getName()+"余额"+balance);
        }
        return balance;
    }

    public MoneyCallable(boolean flag, Integer money) {
        this.flag = flag;
        this.money = money;
    }

    public Integer getBalance() {
        return balance;
    }

    public void setBalance(Integer balance) {
        this.balance = balance;
    }
}
